<?php
/**
 * User
 * 
 * @author dell
 * @version 
 */
require_once 'Zend/Db/Table/Abstract.php';
class Application_Model_User extends Zend_Db_Table_Abstract {
	/**
	 * The default table name 
	 */
	protected $_name = 'normal_user';
	
	// 子表
	protected $_dependentTables = array('Application_Model_Auction', 
		'Applicaton_Model_Winner', 'Application_Model_Topup');
	
	public function getUser($platform, $platform_id) {
		$row = $this->fetchRow ( 'platform = "' . $platform . '" and platform_id = "' . $platform_id . '"');
		return $row;
	}
	
	public function getUserById($id) {
		$row = $this->fetchRow ( 'id = ' . $id );
		return $row;
	}
	
	public function addPaidToken($id, $paidToken) {
		$db = Zend_Db_Table_Abstract::getDefaultAdapter();  
		$origin = $db->fetchOne("select paid_token from $this->_name where id=" . $id);
		echo $origin;
		$total = $origin + $paidToken;
		try {
			$this->update(array('paid_token'=>$total), array('id'=>$id));
		} catch(Exception $e) {
			echo 'addPaidToken 更新出错';
			return false;
		}
		return true;
	}
}
